package com.ecoolex.discount.sales.enums;

import com.ecoolex.discount.sales.entity.DiscountOrder;
import com.ecoolex.framework.common.EnumInterface;
import com.ecoolex.framework.common.util.Check;

public enum DiscountOrderStatus implements EnumInterface<DiscountOrderStatus, Integer> {
	CREATE(1, "创建订单"),
	CANCEL(10, "取消"),
	PAID(20, "支付"),
	PROCESS(30, "处理"),
	REFUND(40, "退款"),
	COMPLETE(50, "完成"),
	EXPIRED(60, "过期"),
	;

	private int real;

	private String describe;

	private DiscountOrderStatus(int real, String describe) {
		this.real = real;
		this.describe = describe;
	}

	@Override
	public Integer real() {
		return real;
	}

	@Override
	public String describe() {
		return describe;
	}

	public static DiscountOrderStatus realValueOf(Integer real) {
		if (Check.notNull(real)) {
			for (DiscountOrderStatus v : values()) {
				if (v.real().equals(real)) {
					return v;
				}
			}
		}
		return null;
	}

	public static boolean canPay(DiscountOrder order) {
		return CREATE.equal(order.getOrderStatus());
	}

	public static boolean canCancel(DiscountOrder order) {
		return CREATE.equal(order.getOrderStatus());
	}

	public static boolean canDel(DiscountOrder order) {
		return CANCEL.equal(order.getOrderStatus());
	}

	public static boolean canRefund(DiscountOrder order) {
		return PAID.equal(order.getOrderStatus()) || PROCESS.equal(order.getOrderStatus())
			|| COMPLETE.equal(order.getOrderStatus()) || EXPIRED.equal(order.getOrderStatus());
	}
	
	public static boolean canCancelRefund(DiscountOrder order) {
		return REFUND.equal(order.getOrderStatus()) 
			&& DiscountOrderRefundStatus.APPLY_REFUND.equal(order.getRefundStatus());
	}

	public static boolean canConfirmComplete(DiscountOrder order) {
		return COMPLETE.equal(order.getOrderStatus());
	}
	
	public static boolean canPartConfirmComplete(DiscountOrder order) {
		return PROCESS.equal(order.getOrderStatus());
	}
}
